const mongoose = require('mongoose');
const config = require('../../config/env/config_db.json');

const pathInfo = "mongodb://" + config.MongoDB.context + ":" + config.MongoDB.port + "/" + config.MongoDB.actionDB;

mongoose.Promise = global.Promise;

module.exports = {
    connectMongoDB: connectMongoDB,
    createModel: createModel
}



function connectMongoDB() {
    mongoose.set('debug',true);
    mongoose.connect(pathInfo, { userMongoClient: true })
        .then(function (db) {
            console.log('DB connected');
        })
        .catch(function (error) {
            console.log('DB connect failed');
            console.log(err.stack);
        });
}

function createModel() {
    require('../../app/models/Customer.js');
    require('../../app/models/Food.js');
    require('../../app/models/Merchant.js');
    require('../../app/models/OrderInfo.js');
}

